<template>
  <div class="wrapper">
    <div class="detail" v-loading="loading">
      <div class="title">{{ detailData.title }}</div>
      <div class="content">
        <div class="content-time">
          <span>发布时间:</span>
          <span>{{ detailData.createTime }}</span>
          <span style="float:right">{{ detailData.createUnit }}</span>
        </div>
        <div class="container" v-html="detailData.context" v-if="detailData.type === 1"></div>
        <div class="link" v-else-if="detailData.type === 2">
          <iframe v-for="(item, index) in iframeData" :key="index" frameborder="0" :src="item"></iframe>
        </div>
      </div>
      <div class="bottomDownLoad">
        <p class="downloadText">附件下载</p>
      </div>
    </div>
  </div>
</template>

<script>
import { axiosGetDetailList } from "@/api/portalPublic";
export default {
  name: "portalPublic",
  created () {
    console.log("详情");
    const id = this.$route.query.id;
    if (!id) {
      return;
    }

    this.getDetailFun(id);
  },
  computed: {
    cIframeStyle () {
      let len = this.iframeData.length;
      if (len === 0) {
        return {
          height: 100 + "%"
        };
      }
      return {
        height: 100 / len + "%"
      };
    }
  },
  data () {
    return {
      detailData: {},
      loading: true,
      iframeData: []
    };
  },
  methods: {
    getDetailFun (id) {
      axiosGetDetailList({ id }).then(res => {
        console.log(res);
        this.detailData = res.data.data;
        if (this.detailData.type === 2) {
          let data = JSON.parse(this.detailData.fileContext);
          this.iframeData = data;
        }
        this.loading = false;
      });
    }
  },
  watch: {
    $route () {
      const id = this.$route.query.id;
      if (!id) {
        return;
      }
      this.getDetailFun(id);
    }
  }
};
</script>

<style lang="less" scoped>
.wrapper {
  width: 100%;
  height: 100%;
  overflow: auto;
}
.detail {
  width: 980px;
  height: 100%;
  margin: 0 auto;
  .bottomDownLoad {
    width: 100%;
    padding-bottom: 20px;
    .downloadText {
      height: 30px;
      padding: 0 10px;
      line-height: 30px;
    }
  }
  /deep/ .title {
    height: 60px;
    // padding: 18px 0 18px 18px;
    text-align: center;
    font-weight: bold;
    line-height: 60px;
    font-size: 24px;
    color: #4d4f53;
    letter-spacing: 1px;
    border-bottom: solid 1px #efefef;
  }
  .content {
    // height: calc(100% - 60px);
    padding: 10px;
    // overflow: auto;
    /deep/ p {
      line-height: 30px;
      // color: #4d4f53;
      img {
        display: block;
        // width: 100%;
        // margin-top: 10px;
      }
    }
    .content-time {
      color: #adadad;
      font-size: 14px;
      line-height: 24px;
      height: 24px;
      margin-bottom: 22px;
    }
    .container {
      // height: calc(100% - 42px);
      overflow: auto;
    }
    .link {
      width: 100%;
      // height: calc(100% - 42px);
      overflow: auto;
      iframe {
        width: 100%;
        height: 500px;
      }
    }
  }
}
</style>
